package bravo.xc.com.xc_bravo_android.operation.messagedetails;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import bravo.xc.com.xc_bravo_android.R;
import bravo.xc.com.xc_bravo_android.base.BaseMVPActivity;
import bravo.xc.com.xc_bravo_android.beans.OrderDetailsBeans;
import bravo.xc.com.xc_bravo_android.beans.OrderDetailsResultBeans;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class MessageDetailsActivity extends BaseMVPActivity<MessageDetailsContract.OrderDetailsView,MessageDetailsContract.OrderDetailsPresenter> implements MessageDetailsContract.OrderDetailsView,View.OnClickListener{

    private LinearLayout layout_title_left;
    private TextView tv_title_meg,orderNum,orderMoney,orderStatus,orderPeople,orderTime,orderType;
    private OrderDetailsBeans orderDetailsBeans;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_title_left:
                finish();
                break;
        }
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(MessageDetailsActivity.this,str,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected MessageDetailsContract.OrderDetailsPresenter createPresnter() {
        return new MessageDetailsPresenter();
    }

    @Override
    protected void initView() {
        layout_title_left=(LinearLayout)findViewById(R.id.layout_title_left);
        tv_title_meg=(TextView)findViewById(R.id.tv_title_msg);
        orderNum=(TextView)findViewById(R.id.Order_Num);
        orderMoney=(TextView)findViewById(R.id.Order_money);
        orderStatus=(TextView)findViewById(R.id.Order_status);
        orderPeople=(TextView)findViewById(R.id.Order_people);
        orderTime=(TextView)findViewById(R.id.Order_time);
        orderType=(TextView)findViewById(R.id.Order_type);
        tv_title_meg.setText("订单详情");
        layout_title_left.setOnClickListener(this);
    }

    @Override
    protected void initData() {

        orderDetailsBeans = new OrderDetailsBeans();
        orderDetailsBeans.setOrderNum(getIntent().getStringExtra("orderNum"));
        presenter.doGetOrder(orderDetailsBeans);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_message_details;
    }

    @Override
    protected Unbinder getBinder() {
        return ButterKnife.bind(this);
    }

    @Override
    protected void onChildDestroy() {
        presenter.onDetached();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public void setOrder(OrderDetailsResultBeans orderDetailsResultBeans) {

        orderNum.setText(String.valueOf(orderDetailsResultBeans.getData().get(0).getOrderNum()));
        orderMoney.setText(String.valueOf(orderDetailsResultBeans.getData().get(0).getSum())+"元");
        switch (orderDetailsResultBeans.getData().get(0).getStatus()){
            case 0:
                orderStatus.setText("已购买");
                break;
            case 1:
                orderStatus.setText("已付款");
                break;
            case 2:
                orderStatus.setText("已完成");
                break;
            default:
                orderStatus.setText("");

        }
        orderPeople.setText(orderDetailsResultBeans.getName());
        orderTime.setText(orderDetailsResultBeans.getData().get(0).getOverTime());
        orderType.setText(orderDetailsResultBeans.getData().get(0).isType()?"线上":"线下");

    }
}
